<?php

namespace App\Ship\Traits;

use App\Ship\Criterias\Where;
use Carbon\Carbon;

trait FilterByDateTrait
{
    public function filterByDate($from, $to): self
    {
        if (!empty($from)) {
            $this->repository->pushCriteria(
                new Where('created_at', '>=', Carbon::parse($from))
            );
        }

        if (!empty($to)) {
            $this->repository->pushCriteria(
                new Where('created_at', '<=', Carbon::parse($to))
            );
        }

        return $this;
    }
}
